<?php
	if (!defined('EXPONENT')) exit('');
	if (exponent_permissions_check(array('administrate','configure',"create"),$loc)){
		
		$id=0;
		if (isset($_REQUEST['id']))
			$id=intval($_REQUEST['id']);
		
		if (isset($_REQUEST['type'])) // type=company
			// for category, sub grid, list company
			$sql = "SELECT {$db->prefix}surveymodule_companies.* 
		FROM {$db->prefix}surveymodule_companies INNER JOIN {$db->prefix}surveymodule_companies_services 
		ON {$db->prefix}surveymodule_companies_services.company_id = {$db->prefix}surveymodule_companies.id
		WHERE (location_data = '".serialize($loc)."') AND (cat_id = {$id})";
		else
			// for company, subgrid, list services
			$sql = "SELECT {$db->prefix}surveymodule_catergory.* 
		FROM {$db->prefix}surveymodule_catergory INNER JOIN {$db->prefix}surveymodule_companies_services 
		ON {$db->prefix}surveymodule_companies_services.cat_id = {$db->prefix}surveymodule_catergory.id
		WHERE (location_data = '".serialize($loc)."') AND (company_id = {$id})";
		
		$data=$db->selectObjectsBySql($sql);
		
		$ret_object = null;
		$ret_object->total = count($data);
		$ret_object->rows = $data;
		
		echo json_encode($ret_object);
	}
	die();
?>